<?php
	error_reporting(E_ALL);
	include_once('simple_html_dom.php');
    // verzija bez jQuery style i class atributa, original HTML
	if(isset($_POST['imefajla'])) {
        $original = $_POST['imefajla'];
    } else {
        $original = '../original';
    };
	$baseUrl = 'http://localhost/kooperacija2013/';
	$originalUrl = $baseUrl.'verzije/datum/'.$original.'.html';
	$html = file_get_html($originalUrl);

    // verzija sa jQuery style i class atributima
    $styleUrl = $baseUrl.'verzije/datum/'.$original.'-stil.html';
    $html2 = file_get_html($styleUrl);

    // get style attr
    $stil[] = '';
    $aria[] = '';
    foreach($html2->find('#organogram ul li p') as $element) {
    	
    	if(isset($element->style)) {
        	$stil[] = $element->style;
    	} else {
    		array_push($stil, 'font-style:normal');
    	}
    	if(isset($element->ariadisabled)) {
        	$aria[] = $element->ariadisabled;
    	} else {
    		array_push($aria, 'none');
    	}
    }
    // get class names
    $class[] = '';
    foreach($html2->find('.organogramnovi tbody tr td div') as $element) {
    	
    	if(isset($element->class)) {
        	$class[] = $element->class;
    	} else {
    		array_push($class, ' novaklasa ');
    	}
    }
    $class2[] = '';
    foreach($html2->find('.organogramnovi tbody tr td > span.prvispan') as $element) {
    	
    	if(isset($element->class)) {
        	$class2[] = $element->class;
    	} else {
    		array_push($class2, ' novaklasa ');
    	}
    }
    $class3[] = '';
    foreach($html2->find('.organogramnovi') as $element) {
    	
    	if(isset($element->class)) {
        	$class3[] = $element->class;
    	} else {
    		array_push($class3, ' novaklasa ');
    	}
     
    }
    //get raw elements
    $kutijenove[] = '';
	foreach($html->find('.organogramnovi tbody tr td div') as $code) {
		$kutijenove[] = $code;
	}
	$span[] = '';
	foreach($html->find('.organogramnovi tbody tr td > span.prvispan') as $code) {
		$span[] = $code;
	}
	$organogramnovi[] = '';
	foreach($html->find('.organogramnovi') as $code) {
		$organogramnovi[] = $code;
	}
    $kutije[] = '';
	foreach($html->find('#organogram ul li p') as $code) {
		$kutije[] = $code;
	}

	// set style and class to raw elements
    for ($i=1; $i < (count($kutije)); $i++) {
		$kutije[$i]->style = $stil[$i];
		$kutije[$i]->ariadisabled = $aria[$i];

		if($kutije[$i]->ariadisabled == 'true') {
        	$kutije[$i]->class .= ' prvobitno ';
    	} else {
    		$kutije[$i]->class .= ' spusteno ';
    	}

	}
	for ($i=1; $i < (count($kutijenove)); $i++) {
		$kutijenove[$i]->class = $class[$i];
	}
	for ($i=1; $i < (count($span)); $i++) {
		$span[$i]->class = $class2[$i];
	}
	for ($i=1; $i < (count($organogramnovi)); $i++) {
		$organogramnovi[$i]->class = $class3[$i];
	}

	echo $html;
?>